import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    redirect: "/comic", // 或直接指向某个默认页面
    meta: {
      title: "漫画网-免费在线平台",
    },
    // 或直接配置首页组件：
    // component: () => import("@/pages/home/index.vue"),
    // name: "root",
  },
  {
    path: "/home",
    component: () => import("@/pages/home/home.vue"),
    name: "home", // 命名与带参数的路由区分
    meta: {
      title: "漫画网-免费在线平台",
    },
  },
  // {
  // 	path: "/home/:courseId/:code",
  // 	component: () => import("@/pages/home/index.vue"),
  // 	name: "home",
  // 	meta: {
  // 		title: "漫画网-免费在线平台",
  // 	}
  // },
  {
    path: "/det/:id",
    component: () => import("@/pages/det/det.vue"),
    name: "det",
    meta: {
      title: "漫画",
    },
  },
  {
    path: "/classifys",
    component: () => import("@/pages/classify/classify.vue"),
    name: "classifys",
    meta: {
      title: "分类",
    },
  },
  {
    path: "/classify/:id",
    component: () => import("@/pages/classify/classify.vue"),
    name: "classify",
    meta: {
      title: "分类",
    },
  },
  {
    path: "/accountLogin",
    component: () => import("@/pages/login/accountLogin.vue"),
    name: "accountLogin",
    meta: {
      title: "登录",
    },
  },
  {
    path: "/login",
    component: () => import("@/pages/login/login.vue"),
    name: "login",
    meta: {
      title: "登录",
    },
  },
  {
    path: "/phoneLogin",
    component: () => import("@/pages/login/phoneLogin.vue"),
    name: "phoneLogin",
    meta: {
      title: "登录",
    },
  },
  {
    path: "/changePwd",
    component: () => import("@/pages/login/changePwd.vue"),
    name: "changePwd",
    meta: {
      title: "修改密码",
    },
  },
  {
    path: "/comic",
    component: () => import("@/pages/comic/comic.vue"),
    name: "comic",
    meta: {
      title: "首页",
      keepAlive: true,
    },
  },
  {
    path: "/search",
    component: () => import("@/pages/search/search.vue"),
    name: "search",
    meta: {
      title: "搜索",
    },
  },
  {
    path: "/my",
    component: () => import("@/pages/my/my.vue"),
    name: "my",
    meta: {
      title: "我的",
    },
  },
  {
    path: "/setting",
    component: () => import("@/pages/my/setting.vue"),
    name: "setting",
    meta: {
      title: "设置",
    },
  },
  {
    path: "/accountSecurity",
    component: () => import("@/pages/my/accountSecurity.vue"),
    name: "accountSecurity",
    meta: {
      title: "账号与安全",
    },
  },
  {
    path: "/special",
    component: () => import("@/pages/comic/special.vue"),
    name: "special",
    meta: {
      title: "专题",
    },
  },
  {
    path: "/favorite",
    component: () => import("@/pages/favorite/favorite.vue"),
    name: "favorite",
    meta: {
      title: "我的收藏",
    },
  },
  // 排行
  {
    path: "/ranking",
    component: () => import("@/pages/rankingPage/rankingPage.vue"),
    name: "rankingPage",
    meta: {
      title: "榜单",
      keepAlive: true,
    },
  },
  // 关注我们
  {
    path: "/jionus",
    component: () => import("@/pages/jionUs/jionUs.vue"),
    name: "jionus",
    meta: {
      title: "关注我们",
      keepAlive: false,
    },
  },
  // 商务合作
  {
    path: "/cooperation",
    component: () => import("@/pages/cooperation/cooperation.vue"),
    name: "cooperation",
    meta: {
      title: "商务合作",
      keepAlive: false,
    },
  },
  // 意见反馈列表
  {
    path: "/opinionPage",
    component: () => import("@/pages/opinionPage/opinionPage.vue"),
    name: "opinionPage",
    meta: {
      title: "反馈记录",
      keepAlive: false,
    },
  },
  // 新建意见反馈
  {
    path: "/createopinion",
    component: () => import("@/pages/opinionPage/createOpinion.vue"),
    name: "createOpinion",
    meta: {
      title: "意见反馈",
      keepAlive: false,
    },
  },
  // 广场
  {
    path: "/square",
    component: () => import("@/pages/squarePage/squarePage.vue"),
    name: "squarePage",
    meta: {
      title: "广场",
      keepAlive: true,
    },
  },
  // 写真详情
  {
    path: "/squareDetail",
    component: () => import("@/pages/squarePage/squareDetail.vue"),
    name: "squareDetail",
    meta: {
      title: "广场详情",
      keepAlive: false,
    },
  },
  // 关于怪兽漫画
  {
    path: "/basicInfo",
    component: () => import("@/pages/my/basicInfo.vue"),
    name: "basicInfo",
    meta: {
      title: "关于怪兽漫画",
      keepAlive: false,
    },
  },
  // 基本信息
  {
    path: "/userInfo",
    component: () => import("@/pages/my/userInfo.vue"),
    name: "userInfo",
    meta: {
      title: "基本信息",
      keepAlive: false,
    },
  },
  // 绑定手机
  {
    path: "/bandPhone",
    component: () => import("@/pages/my/bandPhone.vue"),
    name: "bandPhone",
    meta: {
      title: "绑定手机",
      keepAlive: false,
    },
  },
  // 历史阅读
  {
    path: "/readHistory",
    component: () => import("@/pages/readHistory/readHistory.vue"),
    name: "readHistory",
    meta: {
      title: "历史阅读",
      keepAlive: false,
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    // 始终滚动到顶部
    return {
      top: 0,
    };
  },
});

// 全局前置守卫
router.beforeEach((to) => {
  // 设置页面标题
});

export default router;
